/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-09-08
 * Time: 16:36
 */
class Counter6 {
    private static Object locker = new Object();
    public int count;
    public void increase() {
        synchronized (locker) {
            count++;
        }
    }
}

public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        Counter6 counter6 = new Counter6();
        Thread t1 = new Thread(() -> {
            for(int i = 0; i < 10000; i++) {
                counter6.increase();
            }
        });

        Thread t2 = new Thread(() -> {
            for(int i = 0; i < 10000; i++) {
                counter6.increase();
            }
        });

        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(counter6.count);
    }
}
